import java.util.*;
import java.io.*;
public class Main implements Serializable{
	private static final long serialVersionUID = 1L;
	String name;
	String number;
	int age;
	String sex;
	public Main(String x,String y,int z,String m)
	{
		name=x;
		number=y;
		age=z;
		sex=m;
	}
	public String toString()
	{
		return name+'\t'+number+"\t"+age+"\t"+sex;
	}
	public static void main(String[] args) {
		Main a=new Main("张三","01",20,"男");
		Main b=new Main("李四","02",21,"男");
		Main c=new Main("王五","03",22,"女");
		List<Main>list=new ArrayList<>();
		list.add(a);
		list.add(b);
		list.add(c);
		try {
			ObjectOutputStream m=new ObjectOutputStream(new FileOutputStream("D:\\list.txt"));
			m.writeObject(list);
			m.flush();
			m.close();
			ObjectInputStream s=new ObjectInputStream(new FileInputStream("D:\\list.txt"));
			ArrayList<?> n=null;
			try {
				n = (ArrayList<?>)s.readObject();
				for(int i=0;i<n.size();i++)
				System.out.println(n.get(i));
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
			s.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}	
	}	
}
